Happy:
今日iT邦主動幫我昇升至 iT邦新手 第 4 級!真是一個全方位的技術網站
ansible 加上條件判斷:
- hosts: web5
name: play-test
vars:
seq:
- 1
- 2
- 3
- 4
tasks:
- name: debug test
debug:
msg: "{{item}}" #單循環
with_items: "{{ seq }}" #單循環
when: item >= 3 #當項目>=3
跑出來如以下:(大等於3才會印出來)
joulong@joulong1:~/playbook$ ansible-playbook playbook5.yml -i inventory.ini
PLAY [play-test] *********************************************************************************************************************************************************************************************
TASK [Gathering Facts] ***************************************************************************************************************************************************************************************
ok: [joulong2]
ok: [joulong3]
TASK [debug test] ********************************************************************************************************************************************************************************************
skipping: [joulong2] => (item=1)
skipping: [joulong2] => (item=2)
ok: [joulong2] => (item=3) => {
"msg": 3
}
skipping: [joulong3] => (item=1)
ok: [joulong2] => (item=4) => {
"msg": 4
}
skipping: [joulong3] => (item=2)
ok: [joulong3] => (item=3) => {
"msg": 3
}
ok: [joulong3] => (item=4) => {
"msg": 4
}